package com.xsz.repository;

import com.xsz.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface UserRepository extends JpaRepository<User,String> {

    public User findByNameAndPwd(String name, String pwd);
    public List<User> findByNameLike(String name);
    public User findByName(String name);
    public User findByIdAndPwd(String id, String pwd);
    public List<User> findByRole(Integer role);

    @Transactional
    @Modifying
    @Query("update User u set u.pwd = ?1 where u.id = ?2")
    public void updatePwdById(String pwd, String id);

    @Transactional
    @Modifying
    @Query("update User u set u.role = ?1 where u.id = ?2")
    public int updateRoledById(Integer role, String id);

}
